<!DOCTYPE html>
<#assign ctx=Session.basePath>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加关注</title>
    <link href="${ctx}/easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <link href="${ctx}/easyui/themes/icon.css" rel="stylesheet" />
    <link href="${ctx}/inspiniain/font-awesome/css/font-awesome.css" rel="stylesheet">
    <script src="${ctx}/js/jquery-1.12.2.min.js"></script>
    <script src="${ctx}/easyui/jquery.easyui.min.js"></script>
    <script src="${ctx}/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="${ctx}/map/js/tool.js"></script>
    <script src="${ctx}/pagination/js/layer/layer.js"></script>
</head>
<body>

<div id="tb" style="padding:5px;height:auto">
    <div>
        关键字：
        <input id="key" class="easyui-text" style="width:200px" placeholder="请输入船舶名称或MMSI">

        <a href="#" class="easyui-linkbutton btn-search" iconCls="icon-search" style="width: 70px;">查找</a>
    </div>
</div>

<table id="dg"
       data-options="rownumbers:true,singleSelect:true,pagination:true,url:'${ctx}/manage/map/company/aisShip/ajax/list',method:'post',toolbar:'#tb'">
    <thead>
    <tr>
        <th data-options="field:'shipname',width:180">船舶</th>
        <th data-options="field:'mmsi',width:100">MMSI</th>
        <th data-options="field:'add',width:100,align:'center'">操作</th>
    </tr>
    </thead>
</table>
<script type="text/javascript">
    $(function(){
        var pager = $('#dg').datagrid({
            fitColumns:true,
            fit: true,
            loadFilter: function(data){
                if(data != null && data.rows != null){
                    for(var i = 0; i < data.rows.length; i++){
                        var record = data.rows[i];
                        if(record.shipname==null||record.shipname=='')
                        {
                            record.shipname='暂无船名';
                        }
                        var add = "<a href='#' onclick='addFocus(\""+record.shipname+"\",\""+record.mmsi+"\")'>添加关注</a>";
                        record.add = add;
                    }
                }
                return data;
            }
        });	// get the pager of datagrid

        $(".btn-search").click(function () {
            $('#dg').datagrid("load",{
                key : $("#key").val(),
            })
        })
    })

    function getGZ(){
        var str = "<option value=''>--请选择分组--</option>";
        $.ajax({
            type: "POST",
            async:false,
            url: "/ship/guanzhu/ajax/groupList",
            data: {},
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    str = str + "<option value='" + data[i].id + "'>" + data[i].name + "</option>";
                }
            }
        });
        return str;
    }

    function addFocus(shipname,mmsi) {
       var gz=getGZ();
        var content="<div style='margin:10px 0 0 10px'><span style='font-size: 14px'>船名:&nbsp;"+shipname+"</span></div>" +
                "<div style='margin:10px 0 0 10px'><span style='font-size: 14px'>MMSI:&nbsp;"+mmsi+"</span></div>" +
                "<div  style='margin: 10px 0 0 10px'><label for='guanid' style='font-size: 14px'>分组:</label>&nbsp;<select id='guanid'>"+gz+"</select></div>";
     var l=layer.open({
            type: 1,
            title: '添加关注',
            shadeClose: false,
            shade: 0.5,
            area: ['250px','200px'],
            content:content,
            btn:['关注','取消'],
            yes:function () {

               var id=$("#guanid").val();
                if(id=='')
                {
                    layer.msg("请选择组别！");
                }else {
                    $.ajax({
                        type: "POST",
                        url: "/manage/ship/user/addship",
                        data: {mmsi:mmsi ,id:id,name:shipname},
                        dataType: "json",
                        success: function (data) {
                            if(data.result == true){
                                layer.close(l);
                                layer.msg("添加成功！");
                            }else{
                                layer.msg("您已关注该船舶！");
                            }
                        }
                    });
                }


            },
            btn2:function () {

            },
            end:function () {

            }
        })
    }
</script>


</body>
</html>